package is.client.ui;

import java.util.Comparator;

/**
 * @author aspr0
 *         Date: 31.05.12
 *         Time: 17:11
 */
public class TableComparator implements Comparator<String>

{
    private boolean comparingNumberValues;

    public TableComparator(int sectionNum, int colNum)
    {
        switch (sectionNum)
        {
            case 0:
                switch (colNum)
                {
                    case 0:
                    case 5:
                    case 6:
                        comparingNumberValues = true;
                        break;

                    default:
                        comparingNumberValues = false;
                }
                break;

            case 1:
                switch (colNum)
                {
                    case 0:
                        comparingNumberValues = true;
                        break;

                    default:
                        comparingNumberValues = false;
                }
                break;
        }
    }

    @Override
    public int compare(String s, String s1)
    {
        return (comparingNumberValues) ? compareNumberValues(s, s1) : compareStringValues(s, s1);
    }

    private int compareStringValues(String s, String s1)
    {
//        Collator collator = Collator.getInstance();
//        collator.setStrength(0);

//        return collator.compare(s, s1);
        return s.compareTo(s1);
    }

    private int compareNumberValues(String s, String s1)
    {
        /* removing spaces allowed in telephone */
        s = s.replaceAll(" ", "");
        s1 = s1.replaceAll(" ", "");

        return Integer.parseInt(s) - Integer.parseInt(s1);
    }
}
